﻿Imports Equipment.DataAccess
Imports Equipment.Business

Public Class RequirementDetailWrapper
    Inherits Requirement

#Region "Properties"

    Public ReadOnly Property FrequencyDescription As String
        Get
            Return Requirement.GetFrequencyDescriptionByType(Me.FrequencyType)
        End Get
    End Property

    Public ReadOnly Property MeasureDescriptions As String
        Get
            Return String.Join(", ", Me.Measures.Select(Function(m) m.MeasureDescription))
        End Get
    End Property


    Public ReadOnly Property CreatedByUserFullName As String
        Get
            Return If(Me.CreatedByUser IsNot Nothing, Me.CreatedByUser.FullName, String.Empty)
        End Get
    End Property

    Public ReadOnly Property AssetTypeDescription As String
        Get
            Return Me.AssetType.Description
        End Get
    End Property

    Public ReadOnly Property RequirementTypeDescription As String
        Get
            Return RequirementTypeLookup.GetDescriptionByType(Me.Type)
        End Get
    End Property

    Public ReadOnly Property FormatedCreatedDate As String
        Get
            Return Me.CreatedDate.ToString("dd/MM/yy hh:mm tt")
        End Get
    End Property

    Public ReadOnly Property TimeUsage As String
        Get
            Dim result As New List(Of String)
            If Me.UseNotHolidayWeekday Then
                result.Add("Weekdays that are not holidays")
            End If
            If Me.UseSaturdays Then
                result.Add("Saturdays")
            End If
            If Me.UseSundays Then
                result.Add("Sundays")
            End If
            If Me.UseHoliday Then
                result.Add("Holidays")
            End If

            Return String.Join(", ", result)
        End Get
    End Property

    Public ReadOnly Property FrequencyInfo As String
        Get
            Select Case Me.FrequencyType
                Case RequirementFrequency.EveryXDays
                    Return String.Format("Every {0} days", Me.Frequency.Value)
                Case RequirementFrequency.EveryXHours
                    Return String.Format("Every {0} hours", Me.Frequency.Value)
                Case RequirementFrequency.EveryXMonth
                    Return String.Format("Every {0} month", Me.Frequency.Value)
                Case RequirementFrequency.EveryXWeeks
                    Return String.Format("Every {0} weeks", Me.Frequency.Value)
                Case RequirementFrequency.EveryXYears
                    Return String.Format("Every {0} years", Me.Frequency.Value)
                Case RequirementFrequency.TwiceDaily
                    Return String.Format("Twice daily: {0}, {1}", Me.FirstTime.Value.ToString("hh:mm tt"), Me.SecondTime.Value.ToString("hh:mm tt"))
            End Select
            Return ""
        End Get
    End Property

    Public ReadOnly Property CreatedByFullName As String
        Get
            Return Me.CreatedByUser.FullName
        End Get
    End Property


#End Region

    Public Shared Function GetFrom(ByVal r As Equipment.DataAccess.Requirement) As RequirementDetailWrapper
        Dim w As New RequirementDetailWrapper

        w.AssetType = r.AssetType
        w.FrequencyType = r.FrequencyType
        w.ID = r.ID
        w.Name = r.Name
        w.Type = r.Type
        w.Measures = r.Measures
        w.CreatedDate = r.CreatedDate
        w.CreatedByUser = r.CreatedByUser
        w.Frequency = r.Frequency
        w.FirstTime = r.FirstTime
        w.SecondTime = r.SecondTime
        w.UseHoliday = r.UseHoliday
        w.UseNotHolidayWeekday = r.UseNotHolidayWeekday
        w.UseSundays = r.UseSundays
        w.UseSaturdays = r.UseSaturdays

        Return w
    End Function
End Class
